home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / opening.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-25  |  1.3 KB  |  59 lines  |  [TEXT/R*ch]

  1. #include "comment.header"
  2.  
  3. extern long int rd;
  4. extern int MAXX, MAXY;
  5. extern void uRandom(long int*);
  6.  
  7. int opening(int *i, int *j, int *cnd, int type)
  8.      /* get move for opening from game tree */
  9. {
  10.   struct tnode {
  11.     int i, j, ndct, next[8];
  12.   };
  13.   
  14.   static struct tnode tree[] = {
  15.     {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},    /* 0 */
  16.     {2, 3, 2, { 8, 9}},
  17.     {2, 4, 1, {10}},
  18.     {3, 2, 2, {11, 12}},
  19.     {3, 3, 6, {14, 15, 16, 17, 18, 19}},
  20.     {3, 4, 1, {10}},  /* 5 */
  21.     {4, 2, 1, {13}},
  22.     {4, 3, 1, {13}},
  23.     {4, 2, 0},
  24.     {4, 3, 0},
  25.     {3, 2, 0},  /* 10 */
  26.     {2, 4, 0},
  27.     {3, 4, 0},
  28.     {2, 3, 0},
  29.     {2, 5, 1, {10}},
  30.     {2, 6, 1, {10}},  /* 15 */
  31.     {3, 5, 1, {10}},
  32.     {5, 2, 1, {13}},
  33.     {5, 3, 1, {13}},
  34.     {6, 2, 1, {13}},
  35.     {2, 2, 0}  /* 20 */
  36.   };
  37.   int m;
  38.   
  39.   /* get i, j */
  40.   if ((type == 1) || (type == 3))
  41.     *i = ((MAXX-1) - tree[*cnd].i)  ;   /* inverted */
  42.   else
  43.     *i = tree[*cnd].i  ;
  44.   if ((type == 2) || (type == 3))
  45.     *j = ((MAXY-1) - tree[*cnd].j)  ;   /* reflected */
  46.   else
  47.     *j = tree[*cnd].j  ;
  48.   if (tree[*cnd].ndct)  /* more move */
  49.     {
  50.       uRandom(&rd);
  51.       m = rd % tree[*cnd].ndct;  /* select move */
  52.       *cnd = tree[*cnd].next[m];    /* new    current node */
  53.       return 1;
  54.     }
  55.   else
  56.     return 0;
  57. }  /* end opening */
  58.  
  59.